< previous page page_63 next page >

Page 63
   res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _
   "SYSTEM\CurrentControlSet\Control\" & Listl.Text, _
   0, KEY_READ, KeyToCheck)
   ' This should always work, but we'll be cautious
   If res = 0 Then
      Call DisplayValue(KeyToCheck, List2.Text)
      Call RegCloseKey(KeyToCheck)
   End If
End Sub
The DisplayValue function uses the RegQueryValueEx function to read the registry value. This function is defined in the Microsoft documentation as follows:
LONG RegQueryValueEx(
    HKEY hKey,                    // handle of key to query
    LPTSTR lpValueName,           // address of name of value to query
    LPDWORD lpReserved,           // reserved - Must be NULL
    LPDWORD lpType,               // address of buffer for value type
    LPBYTE lpData,                // address of data buffer
    LPDWORD lpcbData              // address of data buffer size
   );
The hKey parameter is a handle to the open key, a Long value as always. The lpValueName parameter is the name of the value. The lpReserved parameter should be NULL. The lpType parameter is a pointer to a Long variable. This variable will be loaded with a constant describing the type of data in this registry entry. A partial list of variable types is presented in Table P14-1.
REG_NONE = 0No value type
REG_SZ = 1NULL-terminated string
EG_EXPAND_SZ = 2NULL-terminated string with references to environment variables that have not yet been expanded.
REG_BINARY = 3Binary data
REG_DWORD = 432-bit Long value
REG_MULTI_SZ = 7Series of strings separated by NULL characters and terminated by two NULL characters.
Table P14-1: Partial list of registry data types

The string data is stored in the registry as Unicode strings, but the ANSI version of the RegQueryValueEx function retrieves ANSI strings.

 
< previous page page_63 next page >